package inabit.inabitcompiler.productions.values;

import inabit.compiler.parser.grammar.NonTerminal;
import inabit.compiler.parser.grammar.Production;
import inabit.compiler.parser.grammar.Symbol;
import inabit.compiler.parser.grammar.Terminal;
import inabit.inabitcompiler.lexical.InabitTokenClass;
import inabit.inabitcompiler.parser.InabitSemanticAction;

/**N -> -N*/
/**@author Rafael Rocha*/
public class N_Rule3 extends Production{
	private NonTerminal N;
	
	public N_Rule3() {
		super("N");
	}

	@Override
	protected Symbol[] production(final NonTerminal nonTerminal) {
		N = new NonTerminal("N");
		Symbol[] symbols = {
				new Terminal(InabitTokenClass.MINUS),
				N,
				new InabitSemanticAction(nonTerminal) {
					
					@Override
					public void execute() throws Exception {
						if(N.code.charAt(0) == '-') {
							nonTerminal.code = N.code.substring(1);
						}else {
							nonTerminal.code = "-" + N.code;
						}
					}
				}
		};
		return symbols;
	}
}
